package com.lin.stockbackend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lin.stockbackend.common.BaseResponse;
import com.lin.stockbackend.common.ErrorCode;
import com.lin.stockbackend.common.PageRequest;
import com.lin.stockbackend.common.ResultUtils;
import com.lin.stockbackend.exception.BusinessException;
import com.lin.stockbackend.model.entity.StockBoard;
import com.lin.stockbackend.service.StockBoardService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/stock_board")
public class StockBoardController {

    @Resource
    private StockBoardService stockBoardService;

    /**
     * 分页查询股票板块
     */
    @PostMapping("/list/page")
    public BaseResponse<Page<StockBoard>> listStockBoard(@RequestBody PageRequest pageRequest) {
        if (pageRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        long current = pageRequest.getCurrent();
        long pageSize = pageRequest.getPageSize();
        Page<StockBoard> stockBoardPage = stockBoardService.page(new Page<>(current, pageSize));
        return ResultUtils.success(stockBoardPage);
    }
}
